<?php
	function f130($sql){
		//data handle instance
		//set request
		//define format
		//set format
		//define query string
		//process time
		//process fitler
		$dataHandle = new DataHandle();
		$dataHandle->setRequest("130");

/*		$format = array(
			"Start Time" => "dated/m/Y H:i:s",
			"End Time" => "dated/m/Y H:i:s",
			);

		$dataHandle->setFormat($format);*/

		$dataType = getValue($_GET['dataType']);
		$action = getValue($_GET['action']);

		if ($dataType == "json"){
			$error = $dataHandle->processTime($startTime, $endTime);
			if($error == ""){
				$filter = $dataHandle->processFilters($startTime, $endTime, "mix_Produced_Summary_View","date");
				$query = getJSONQuery($startTime, $endTime, $filter);
				print($dataHandle->printJSON($sql, $query));
			}
			else
				print($error);
		}
		else if($action == "getYears"){
			$query = getYears();
			print($dataHandle->printJSON($sql, $query));
		}
		else{
			$temp = array();
			$temp['error'] = "130: Bad request";
			print(json_encode($temp));
		}

		unset($dataHandle);

	}

	function getJSONQuery(&$startTime, &$endTime, &$filter){
		$queryString = "
			SELECT
				date_formatted AS 'Date',
				shift AS 'Shift',
				available_time AS 'Available',
				dumping_min AS 'Dumping',
				draining_min AS 'Draining',
				picking_min AS 'Picking',
				overhead_min AS 'Overhead'
			FROM mix_Produced_Summary_View";


		$queryString = $queryString.$filter;

		return $queryString;
	}
	function getYears(){
		$queryString = 
			"SELECT DISTINCT 
				DATEPART(year, modified_Date) AS availableYear 
			FROM mix_Products 
			ORDER BY availableYear desc";
		return $queryString;
	}
?>
